using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace SerialPortCommunicationProject
{
    [ValueConversion(typeof(bool), typeof(string))]
    public class IsOpenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool re = (bool)value;
            if (re)
            {
                return "打开";
            }
            else
            {
                return "关闭";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool result = false;
            string strValue = value as string;
            if (strValue == "打开")
            {
                result = true;
            }
            if (strValue == "关闭")
            {
                result = false;
            }
            return result;
        }
    }

    [ValueConversion(typeof(bool), typeof(string))]
    public class IsOpenReverseConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool re = !(bool)value;
            if (re)
            {
                return "打开";
            }
            else
            {
                return "关闭";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool result = false;
            string strValue = value as string;
            if (strValue == "打开")
            {
                result = true;
            }
            if (strValue == "关闭")
            {
                result = false;
            }
            return !result;
        }
    }
}

    
